package com.lx.spring.jdbc.dao;

import com.lx.spring.jdbc.entity.OperCord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
//数据模型层
@Repository
public class OperCordDao {

    @Autowired
    JdbcTemplate jdbcTemplate;


    // 查询用户的流水记录
    public List<OperCord> queryBiAid(long aid){
        String sql = "select * from bank_oprecord where aid = ?";
        //BeanPropertyRowMapper 将数据库查询结果转换为Java类对象
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<OperCord>(OperCord.class), aid);
    }

    public void insert(OperCord opercord){
        String sql = "insert into bank_oprecord values(default, ?, ?, ?, now(), ?)";
        jdbcTemplate.update(sql, opercord.getAid(),
                opercord.getOpMoney(),
                opercord.getCharge(),
                opercord.getRemark());

    }

}
